//
//  UITextField+Extension.m
//  BasicFramework
//
//  Created by Rainy on 16/11/3.
//  Copyright © 2016年 Rainy. All rights reserved.
//

#import "UITextField+Extension.h"
#define kTapTag 3698
#import "UIView+Extension.h"
@implementation UITextField (Tools)

//左边图片
-(NSString *)leftImageName
{
    return nil;
}
-(void)setLeftImageName:(NSString *)leftImageName
{
    UIImage *image = [UIImage imageNamed:leftImageName];
    float x = 0;
    float y = 0;
    float height = image.size.height;
    float width = image.size.width + 20.0;
    UIImageView *leftView = [[UIImageView alloc]initWithImage:image];
    leftView.frame = CGRectMake(x, y, width, height);
    leftView.contentMode = UIViewContentModeScaleAspectFit;
    
    self.leftView = leftView;
    self.leftViewMode = UITextFieldViewModeAlways;
}

//间隙
- (CGFloat)leftSpace
{
    return self.leftView.width;
}

- (void)setLeftSpace:(CGFloat)leftSpace
{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0,leftSpace, 30)];
    self.leftView = view;
    self.leftViewMode = UITextFieldViewModeAlways;
}



//提示文字颜色
-(void)setPlaceholderColor:(UIColor *)color
{
    if (color) {
        
        [self setValue:color forKeyPath:@"_placeholderLabel.textColor"];
    }
}
-(UIColor*)placeholderColor
{
    return nil;
}


//提示文字大小
-(void)setPlaceholderFont:(UIFont *)placeholderFont
{
    if (placeholderFont) {
        [self setValue:placeholderFont forKeyPath:@"_placeholderLabel.font"];
        
    }
}

-(UIFont *)placeholderFont
{
    return nil;
}


//- (void)setBorderColor:(UIColor *)color
//{
//    if (!color) {
//        color = [UIColor colorWithHexString:@"0xb6b6b6"];
//    }
//    CALayer *textFieldLayer = self.layer;
//    textFieldLayer.borderColor = color.CGColor;
//    textFieldLayer.borderWidth = 1/[UIScreen mainScreen].scale;
//
//}
-(NSString *)isEmpty
{
    if ([self isKindOfClass:[NSNull class]])
    {
        return @"";
    }
    
    return self.text;
}

+(id)TextFieldForImageN:(NSString *)imageN Placeholder:(NSString *)placeholder
{
    UITextField *text = [[self alloc]init];
    text.placeholder = placeholder;
    text.leftImageName = imageN;
    return text;
}

@end


@implementation UITextView (Tools)

-(NSString *)isEmpty
{
    if ([self isKindOfClass:[NSNull class]])
    {
        return @"";
    }
    
    return self.text;
}


@end


@implementation UITextField (Extension)

-(void)LeftImageNamed:(NSString *)Named IMG_size:(CGSize)IMG_size
{
    
    UIImageView *rightView = [[UIImageView alloc]init];
    rightView.image = [UIImage imageNamed:Named];
    rightView.size = IMG_size;
    
    rightView.contentMode = UIViewContentModeCenter;
    // 添加到左侧视图中
    self.leftView = rightView;
    self.leftViewMode = UITextFieldViewModeAlways; // 这句一定要加，否则不显
    
}

@end
